package com.treasure.service.commonutil;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class FileUtil {
	public static BufferedInputStream getImg(String destUrl) {
		BufferedInputStream bis = null;
		HttpURLConnection httpUrl = null;
		URL url = null;
		try {
			url = new URL(destUrl);
			httpUrl = (HttpURLConnection) url.openConnection();
			httpUrl.connect();
			bis = new BufferedInputStream(httpUrl.getInputStream());
		} catch (IOException e) {
		} catch (ClassCastException e) {
		} finally {
			try {
			} catch (Exception e) {
			}
		}
		return bis;
	}
	
	
	public static void saveFile(BufferedInputStream bis) throws Exception{
		int BUFFER_SIZE = 1024;
		byte[] buf = new byte[BUFFER_SIZE];
		int size = 0;
		FileOutputStream fos = new FileOutputStream("F:\\test.png");
		while ((size = bis.read(buf)) != -1) {
			fos.write(buf, 0, size);
		}
		fos.flush();
	};
	public static void main(String[] args) throws Exception {
		saveFile(getImg("http://pie1788fx.bkt.clouddn.com/invite_card_sharepage.png"));
	}
}
